package analysis_uv;

import org.apache.flink.shaded.guava18.com.google.common.hash.BloomFilter;
import org.apache.flink.shaded.guava18.com.google.common.hash.Funnels;
import redis.clients.jedis.Jedis;

/**
 * @author zkq
 * @date 2022/10/5 20:04
 */
public class guava_test {
    public static void main(String[] args) {
        int size = 100000;
        //预计元素为10万个，误差率为百分之1
        BloomFilter<Integer> bloom = BloomFilter.create(Funnels.integerFunnel(), size, 0.01);
        //将1~10万映射到布隆过滤器
        for (int i = 0; i < size; i++) {
            bloom.put(i+1);
        }
        //检查值在过滤其中是否存在
        for (int i = 0; i < size; i++) {
            if(!bloom.mightContain(i+1)){
                System.out.println("存在不匹配的值："+i);
            }
        }
        //检测不在过滤器的1000个值是否有匹配上的，即误差率
        int matchCount = 0;
        for(int i = size+1; i<=size+1000; i++){
            if (bloom.mightContain(i)) {
                matchCount++;
            }
        }
        System.out.println("误判个数为："+matchCount);
    }
}
